import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

def lda(X_train, y_train, X_test, y_test):        
    clf = LDA(n_components=len(set(y_train))-1) #分类器    
    clf.fit(X_train, y_train) #用数据进行训练
    pre_y = clf.predict(X_test) #对测试数据进行预测
    return accuracy_score(y_test,pre_y)

def knn(X_train, y_train, X_test, y_test):
    neigh = KNeighborsClassifier(n_neighbors=5)
    neigh.fit(X_train, y_train)
    y_pre = neigh.predict(X_test)
    return accuracy_score(y_test,y_pre)

